package product

import (
	"chain_bridge_service/internal/pkg/core"
	"chain_bridge_service/internal/repository/mongodb/product"
)

type CreateProductData struct {
	Id           string
	ProductName  string
	Fee          string
	Months       int
	Type         string
	DeleteStatus string
}

func (s *service) Create(ctx core.Context, productData *CreateProductData) (id string, err error) {
	model := product.NewModel()
	model.ProductName = productData.ProductName
	model.Fee = productData.Fee
	model.Months = productData.Months
	model.Type = productData.Type
	model.DeleteStatus = "0"

	id, err = model.Create(s.db.GetDb())
	if err != nil {
		return "", err
	}
	return id, err
}

func (s *service) List(ctx core.Context, pageIndex uint, pageSize uint) (productList []product.Product, err error) {
	model := product.NewModel()
	list, err := model.List(s.db.GetDb(), pageIndex, pageSize)
	return list, err
}

func (s *service) Update(ctx core.Context, productData *CreateProductData) error {
	model := product.NewModel()
	model.ProductName = productData.ProductName
	model.Fee = productData.Fee
	model.Months = productData.Months
	model.Type = productData.Type
	model.Id = productData.Id
	err := model.Update(s.db.GetDb())
	return err

}

func (s *service) Delete(ctx core.Context, productData *CreateProductData) error {
	model := product.NewModel()
	model.Id = productData.Id
	model.DeleteStatus = "1"
	err := model.Delete(s.db.GetDb())
	return err
}

func (s *service) Count(ctx core.Context) (int64, error) {
	model := product.NewModel()
	count, err := model.Count(s.db.GetDb())
	return count, err
}
